package cn.tt.tuantuanerp.passport.webapi.controller;

import cn.tt.tuantuanerp.passport.service.ILoginLogService;
import cn.tt.tuantuanerp.tuantuanerp.comment.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述
 *
 * @author xieyuhao
 * @version 0.0.1
 */
@Api(tags = "登录日志模块")
@Slf4j
@RequestMapping("/loginLog")
@RestController
public class LoginLogController {
    @Autowired
    ILoginLogService iLoginLogService;

    @ApiOperation("登录日志列表")
    @ApiOperationSupport(order = 400)
    @PreAuthorize("hasAuthority('staff_manage')")
    @GetMapping("/{page}/{pageSize}")
    public JsonResult list(@PathVariable Integer page, @PathVariable Integer pageSize){
        log.debug("开始处理[查询登录日志]的请求,page:{},pageSize:{}",page,pageSize);
        return JsonResult.ok(iLoginLogService.listByPage(page, pageSize));
    }

    @ApiOperation("根据姓名查询登录日志列表")
    @ApiOperationSupport(order = 400)
    @PreAuthorize("hasAuthority('staff_manage')")
    @GetMapping("/{username}/{page}/{pageSize}")
    public JsonResult listByUsername(@PathVariable String username,@PathVariable Integer page, @PathVariable Integer pageSize){
        log.debug("开始处理[查询登录日志]的请求,username:{},page:{},pageSize:{}",username,page,pageSize);
        return JsonResult.ok(iLoginLogService.listByPageAndUsername(username,page, pageSize));
    }

    @ApiOperation("登录日志总条数")
    @ApiOperationSupport(order = 400)
    @PreAuthorize("hasAuthority('staff_manage')")
    @GetMapping("/totalData")
    public JsonResult totalData(){
        log.debug("开始处理[查询登录日志总条数]的请求");
        return JsonResult.ok(iLoginLogService.countLoginLog());
    }

    @ApiOperation("根据姓名查询登录日志总条数")
    @ApiOperationSupport(order = 400)
    @PreAuthorize("hasAuthority('staff_manage')")
    @GetMapping("/totalData/{username}")
    public JsonResult totalDataByUsername(@PathVariable String username){
        log.debug("开始处理[查询登录日志总条数]的请求");
        return JsonResult.ok(iLoginLogService.countLoginLog(username));
    }



}
